package Mash.Utility;

import Mash.Map.TerrainMap;
import Mash.Map.FOWMap;
import Mash.Map.UnitMap;
import Mash.Map.BuildingMap;

import java.io.*;
/*Copyright (c)  Sergey Schekochikhin (Genocidicbunny)
 * created on Oct 5, 2009 11:43:19 PM
 */

public class SaveGame {
	public static void saveGame( TerrainMap tmap, BuildingMap bmap, UnitMap umap, FOWMap fmap){
		FileOutputStream fos = null;
		ObjectOutputStream oos = null;
		String uloc = System.getProperty("user.dir");
		System.out.println(uloc);
		File f = new File(uloc + "\\Save\\");
		if(!f.exists())
			f.mkdir();
		System.out.println(uloc + "\\Save\\save.tm");
		try{
			fos = new FileOutputStream(uloc + "\\Save\\save.tm");
			oos = new ObjectOutputStream(fos);
			oos.writeObject(tmap);
			fos = new FileOutputStream(uloc + "\\Save\\save.bm");
			oos = new ObjectOutputStream(fos);
			oos.writeObject(bmap);
			fos = new FileOutputStream(uloc +"\\Save\\save.um");
			oos = new ObjectOutputStream(fos);
			oos.writeObject(umap);
			fos = new FileOutputStream(uloc +"\\Save\\save.fm");
			oos = new ObjectOutputStream(fos);
			oos.writeObject(fmap);
			oos.close();
		}
		catch( FileNotFoundException fnfe){ 
			fnfe.printStackTrace();
		}
		catch( IOException ioe){
			ioe.printStackTrace();
		}

	}
	public static void main(String args[]){
		TerrainMap tm = new TerrainMap(6, 6);
		BuildingMap bm = new BuildingMap(6, 6);
		UnitMap um = new UnitMap(6, 6);
		FOWMap fw = new FOWMap(6, 6, false);
		saveGame(tm, bm, um, fw);
	}
}
